// 重写array的方法
// 自己实现的
// const reactive = (arr) => {
//   const handleArr =  ['push','splice']
//   for (const handle of handleArr) {
//     const originFunc = Array.prototype[handle]
//     Array.prototype[handle] = function (...args) {
//       const self = this
//       console.log(args.join(','))
//       console.log(`Action = ${handle}, args=${args}`)
//       originFunc.call(self,...args)
//     }
//   }
// }

const render = (action, ...args)=>{
  console.log(`Action = ${action}, args=${args.join(',')}`)
}

const arrPrototype = Array.prototype
const newArrPrototype = Object.create(arrPrototype)

const methodArr = ['push','splice']
['push','splice'].forEach(methodName => {
  newArrPrototype[methodName] = function(){
    arrPrototype[methodName].call(this,...arguments)
    render(methodName, ...arguments)
  }
})

const reactive = (arr) => {
  if (Array.isArray(arr)) {
    arr.__proto__ = newArrPrototype
  }
}
const data = [2, 3, 4, 5]

reactive(data)

data.push(5) // Action = push, args=5
data.splice(0, 2) // Action = splice, args=0,2